﻿using System.Windows;
using System.Windows.Controls;
using GIMS.Def.Arguments;

namespace GIMS.GUI.ArgumentControls
{
    /// <summary>
    /// Interaction logic for PathArgumentControl.xaml
    /// </summary>
    public partial class PathArgumentControl : UserControl
    {
        private PathArgumentControlViewModel viewModel;
        public PathArgumentControl(PathArgumentControlViewModel viewModel)
        {
            InitializeComponent();
            this.viewModel = viewModel;
            this.DataContext = viewModel;
        }

        private void choosePathButton_Click(object sender, RoutedEventArgs e)
        {
            if (viewModel.PathArgument.PathType == PathType.load)
            {
                GetLoadPath();
            }
            else if (viewModel.PathArgument.PathType == PathType.save) 
            {
                GetSavePath();
            }
        }

        private void GetLoadPath()
        {
            var dialog = new Microsoft.Win32.OpenFileDialog {Multiselect = false};
            var dialogResult = dialog.ShowDialog();
            if (dialogResult.Value)
            {
                viewModel.PathArgument.Path = dialog.FileName;
            }
        }

        private void GetSavePath()
        {
            var dialog = new Microsoft.Win32.SaveFileDialog();
            dialog.DefaultExt = ".png";
            dialog.Filter = "PNG Image|*.png|JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif";
            if (dialog.ShowDialog() == true)
            {
                viewModel.PathArgument.Path = dialog.FileName;
            }
        }
    }
}
